package com.sgb.kjwl.view.ui.activity.self.packers;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.AtSelfWorkerPublishBinding;
import com.sgb.kjwl.di.self.DaggerSelfComponent;
import com.sgb.kjwl.di.self.SelfModule;
import com.sgb.kjwl.model.entity.self.SelfWorkerPublishEntity;
import com.sgb.kjwl.view.ui.activity.WebViewX5HostActivity;
import com.sgb.kjwl.viewmodel.self.packers.SelfWorkerPublishModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import javax.inject.Inject;

/**
 *  description:新工人发布
 *  @author LiWei
 * @date 2020/12/19
 */
public class SelfWorkerPublishActivity extends AppActivity {

    @Inject
    SelfWorkerPublishModel viewModel;

    public static void start(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, SelfWorkerPublishActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerSelfComponent.builder().
                appComponent(appComponent).selfModule(new SelfModule(this))
                .build()
                .inject(this);
    }

    @Override
    protected boolean statusBarDark() {
        return false;
    }

    @Override
    protected void initView() {
        AtSelfWorkerPublishBinding binding = DataBindingUtil.setContentView(this, R.layout.at_self_worker_publish);
        binding.setViewModel(viewModel);
        binding.inputWorkerInfo.setOnClickListener(this);
        binding.inputWorkExperience.setOnClickListener(this);
        binding.inputCertificate.setOnClickListener(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        viewModel.getWorkerDetail();
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.input_worker_info) {
            SelfBasicInformationActivity.start(this);
        } else if (id == R.id.input_work_experience || id == R.id.input_certificate) {
            MToast.showToast(SelfWorkerPublishActivity.this, "请先完善基础信息");
        }
    }

    public void updateWorkerEntity(SelfWorkerPublishEntity data) {
        if (isFinishing()) {
            return;
        }
        if (data != null && !TextUtils.isEmpty(data.getAge())) {
            viewModel.getH5Url(data.getNo());
        }
    }

    public void requestH5Url(String url) {
        if (isFinishing()) {
            return;
        }
        WebViewX5HostActivity.start(this, url, SelfTeamProjectActivity.REQUEST_CODE);
        DialogHelper.dismissProgressDialog();
        finish();
    }
}
